//<{$lang.warehouse}><{$lang.list}>
function loadSelect(act) {
    $.ajax({
        type:"post",
        async:false,
        dataType:"json",
        url:"/warehouse/shelf/select",
        data:null,
        success:function (json) {
            var list = "";
            if (json.ask == 1) {
                $.each(json.result, function (key, val) {
                    list += "<option value=" + val.warehouse_id + ">" + val.warehouse_name + "</option>";
                });
            }
            list = "<option value=''><{$lang.pls}></option>" + list;
            $("#warehouse_id").html(list);
        }
    });
}

//<{$lang.area}><{$lang.list}>
function loadAreaSelect() {
    $.ajax({
        type:"post",
        async:false,
        dataType:"json",
        url:"/warehouse/area/select",
        data:null,
        success:function (json) {
            var list = "";
            if (json.ask == 1) {
                $.each(json.result, function (key, val) {
                    list += "<option value=" + val.wa_code + ">" + val.wa_name + "</option>";
                });
                list = "<option value=''><{$lang.pls}></option>" + list;
                $("#room_wa_code").html(list);
            }
        }
    });
}

//房间<{$lang.list}>
function loadHouseSelect() {
    $.ajax({
        type:"post",
        async:false,
        dataType:"json",
        url:"/warehouse/house/selectlist",
        data:null,
        success:function (json) {
            var list = "";
            if (json.ask == 1) {
                $.each(json.result, function (key, val) {
                    list += "<option value=" + val.wh_code + ">" + val.wh_code + "</option>";
                });
                list = "<option value=''><{$lang.pls}></option>" + list;
                $("#room_number").html(list);
            }
        }
    });
}


//<{$lang.search}>
var paginationTotal = 1;//记录总数
var paginationPageSize = 60;
var isSearch = false;
function submitShelfSearch() {
    isSearch = true;
    paginationCurrentPage = 1;
    initData(0);
}
$(function () {
    initData(0);
    $(".searchshelf").click(function () {
        submitShelfSearch();
    })
    loadSelect();//<{$lang.warehouse}>
    loadAreaSelect(); //<{$lang.area}>
    //loadHouseSelect();//房间
    $("#shelfdialog").dialog({
        autoOpen:false,
        modal:true,
        width:800,
        title:'<{$lang.pls}><{$lang.ws_code}>',
        show:"slide",
        buttons:{
            'Close':function () {
                $(this).dialog('close');
            }
        }
    });
});

//<{$lang.pls}><{$lang.ws_code}>
function selectshelf(obj,pid) {
    $('#shelfForm')[0].reset();
    if(pid=='')return;
    $("#select_product_id").val(pid);
    initData(0);
    var p = $(obj).parent().html();
    $(".a_select_ws_code").die("click");
    $("#shelfdialog").dialog("open");
    $(".a_select_ws_code").live("click", function () {
        $(obj).parent().children("input").val($(this).html());
        $("#shelfdialog").dialog("close");
        $(".a_select_ws_code").die("click");
    });
}

function loadData(page, pageSize) {
    var  vForm = $("#shelfForm").serializeArray();
    $.ajax({
        type:"POST",
        async:false,
        dataType:"json",
        url:"/product/putaway/get-shelf/page/" + page + "/pageSize/" + pageSize,
        data:vForm,
        success:function (json) {
            var html = "";
            paginationTotal = json.total;
            if (json.ask == 0) {
                html = "<div><{$lang.no_data}></div>";
            } else {
                $.each(json.result, function (k, v) {
                    html += "<div><a class=\"a_select_ws_code\" href=\"javascript:void(0);\">" + v.ws_code + "</a></div>";
                });
            }
            $("#shelfloadData").html(html);
        }
    });
}